﻿<Window x:Class="MainWindow"
        x:Name="WindowRoot"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:EIBWatcherNet.Test"
        Height="640" Width="1138" WindowStartupLocation="CenterScreen"
        FontFamily="Courier New">
    <Window.Title>
        <MultiBinding>
            <MultiBinding.Converter>
                <local:TitleStringConverter />
            </MultiBinding.Converter>

            <Binding TargetNullValue="{StaticResource AppTitle}" />
            <Binding Path="ConnectionState" RelativeSource="{RelativeSource Self}" />
        </MultiBinding>
    </Window.Title>
    <Window.Resources>
        <local:InvertBooleanConverter x:Key="InvertBooleanConverter" />
    </Window.Resources>
    
    <DockPanel>
        <Menu DockPanel.Dock="Top">
            <MenuItem Header="_File">
                <MenuItem x:Name="mnuLoadFromHex" Header="_Load Hex Log" />
                <MenuItem Header="_Save As">
                    <MenuItem x:Name="mnuSaveAsText" Header="_Text File" />
                    <MenuItem x:Name="mnuSaveAsHex" Header="_Hex File" />
                </MenuItem>
                <Separator />
                <MenuItem x:Name="mnuClose" Header="_Close" />
            </MenuItem>
            <MenuItem Header="BCU">
                <MenuItem x:Name="mnuLinkStatus" Header="Get Link Status" IsEnabled="{Binding IsConnected, ElementName=WindowRoot}" />
                <MenuItem x:Name="mnuResetBCU" Header="Reset BCU" IsEnabled="{Binding IsConnected, ElementName=WindowRoot}" />
            </MenuItem>
            <MenuItem Header="_Bus">
                <MenuItem x:Name="mnuConnect" Header="Connect" IsEnabled="{Binding IsConnected, ElementName=WindowRoot, Converter={StaticResource InvertBooleanConverter}}" />
                <MenuItem x:Name="mnuDisconnect" Header="Disconnect" IsEnabled="{Binding IsConnected, ElementName=WindowRoot}" />
                <Separator />
                <MenuItem x:Name="mnuRead" Header="Read Address" IsEnabled="{Binding IsConnected, ElementName=WindowRoot}" />
                <MenuItem x:Name="mnuWrite" Header="Write Address" IsEnabled="{Binding IsConnected, ElementName=WindowRoot}" />
            </MenuItem>
            <MenuItem Header="_Help">
                <Separator />
                <MenuItem x:Name="mnuAbout" Header="About..." />
            </MenuItem>
        </Menu>
        
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition MinWidth="330" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>
            
            <GroupBox Header="Message Log">
                <ListBox x:Name="lbLog" ItemsSource="{Binding}">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Message}" />
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </GroupBox>
            <GroupBox Header="Detailed Message Log" Grid.Row="1">
                <ListView x:Name="lvLog" ItemsSource="{Binding}">
                    <ListView.View>
                        <GridView>
                            <GridViewColumn Header="Timestamp" DisplayMemberBinding="{Binding Timestamp}" />
                            <GridViewColumn Header="Type" DisplayMemberBinding="{Binding Type}" />
                            <GridViewColumn Header="Source Address" DisplayMemberBinding="{Binding SourceAddress}" />
                            <GridViewColumn Header="Destination Address" DisplayMemberBinding="{Binding DestinationAddress}" />
                            <GridViewColumn Header="Value" DisplayMemberBinding="{Binding ValueString}" />
                        </GridView>
                    </ListView.View>
                </ListView>
            </GroupBox>
            <DockPanel Grid.Column="1" Grid.RowSpan="2">
                <StackPanel DockPanel.Dock="Bottom">
                    <GroupBox Header="Bus Access">
                        <TabControl x:Name="tcOptions" Padding="0,10,0,5">
                            <TabItem Header="Bus Access">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition />
                                        <ColumnDefinition Width="5" />
                                        <ColumnDefinition />
                                    </Grid.ColumnDefinitions>
                                                                        
                                    <GroupBox Header="Connection">
                                        <DockPanel>
                                            <Button x:Name="btnRescanPorts" Content="P" FontFamily="Wingdings 3" Margin="5,0,0,0" DockPanel.Dock="Right" />
                                            <ComboBox x:Name="cmbPorts" IsEnabled="{Binding IsConnected, ElementName=WindowRoot, Converter={StaticResource InvertBooleanConverter}}">
                                                <ComboBox.GroupStyle>
                                                    <GroupStyle>
                                                        <GroupStyle.HeaderTemplate>
                                                            <DataTemplate>
                                                                <TextBlock FontWeight="Bold">-- <Run Text="{Binding Name, Mode=OneTime}"/> --</TextBlock>
                                                            </DataTemplate>
                                                        </GroupStyle.HeaderTemplate>
                                                    </GroupStyle>
                                                </ComboBox.GroupStyle>
                                                <ComboBox.ItemTemplate>
                                                    <DataTemplate>
                                                        <TextBlock Text="{Binding PortName}" />
                                                    </DataTemplate>
                                                </ComboBox.ItemTemplate>
                                            </ComboBox>
                                        </DockPanel>
                                    </GroupBox>
                                    <StackPanel VerticalAlignment="Bottom" Grid.Column="2">
                                        <Button x:Name="btnConnect" Content="Connect" Margin="0,0,0,5" Grid.Column="1" IsEnabled="{Binding IsConnected, ElementName=WindowRoot, Converter={StaticResource InvertBooleanConverter}}" />
                                        <Button x:Name="btnDisconnect" Content="Disconnect" Grid.Column="1" IsEnabled="{Binding IsConnected, ElementName=WindowRoot}" />
                                    </StackPanel>
                                </Grid>
                            </TabItem>
                            <TabItem Header="Read Address">
                                <StackPanel Orientation="Horizontal">
                                    <TextBox x:Name="txtReadAddress" Text="2/3/1" TextAlignment="Center" Width="50" />
                                    <Button x:Name="btnRead" Content="Read" IsEnabled="{Binding IsConnected, ElementName=WindowRoot}" />
                                    <Button x:Name="btnReadForce" Content="Force Read" IsEnabled="{Binding IsConnected, ElementName=WindowRoot}" />
                                </StackPanel>
                            </TabItem>
                            <TabItem Header="WriteAddress">
                                <StackPanel Orientation="Horizontal">
                                    <TextBox x:Name="txtWriteAddress" Text="2/3/1" TextAlignment="Center" Width="50" />
                                    <CheckBox x:Name="cbWriteValue" />
                                    <Button x:Name="btnWrite" Content="Write" IsEnabled="{Binding IsConnected, ElementName=WindowRoot}" />
                                </StackPanel>
                            </TabItem>
                            <TabItem Header="BusMon Test">
                                <Button x:Name="btnBusMonTest" Content="Send" />
                            </TabItem>
                        </TabControl>
                    </GroupBox>
                    <GroupBox Header="Status">
                        <StackPanel>
                            <TextBlock Text="..." Margin="5,3,5,5" />
                        </StackPanel>
                    </GroupBox>
                </StackPanel>
                <GroupBox Header="Message Details">
                    <DockPanel>
                        <GroupBox Header="Encode Message Data (DPT)" DockPanel.Dock="Bottom">
                            <StackPanel>
                                <StackPanel Orientation="Horizontal">
                                    <StackPanel>
                                        <ComboBox x:Name="cmbDecodeDPTMainType" ItemsSource="{Binding}" HorizontalContentAlignment="Stretch" Width="150">
                                            <ComboBox.ItemTemplate>
                                                <DataTemplate>
                                                    <Grid>
                                                        <TextBlock>
                                                            <Run Text="{Binding DPT_Number, Mode=OneTime}" /> - <Run Text="{Binding DPT_Name, Mode=OneTime}" />
                                                        </TextBlock>
                                                    </Grid>
                                                </DataTemplate>
                                            </ComboBox.ItemTemplate>
                                        </ComboBox>
                                        <ComboBox x:Name="cmbDecodeDPTSubType" ItemsSource="{Binding}" HorizontalContentAlignment="Stretch" Margin="0,5,0,0" Width="150">
                                            <ComboBox.ItemTemplate>
                                                <DataTemplate>
                                                    <Grid>
                                                        <TextBlock>
                                                            <Run Text="{Binding DPT_Number, Mode=OneTime}" /> - <Run Text="{Binding DPT_Name, Mode=OneTime}" />
                                                        </TextBlock>
                                                    </Grid>
                                                </DataTemplate>
                                            </ComboBox.ItemTemplate>
                                        </ComboBox>
                                    </StackPanel>
                                    <Button x:Name="btnDecodeDPT" Content="Try Decode" Margin="10,0,0,0" />
                                </StackPanel>
                                <StackPanel Margin="0,10,0,0">
                                    <TextBlock Text="Encoded Data: " />
                                    <TextBlock x:Name="txtDecodedDPTData" Text="n/a" Margin="10,3,5,5" />
                                </StackPanel>
                            </StackPanel>
                        </GroupBox>
                        <GroupBox Header="Encode Message Data (EIS)" DockPanel.Dock="Bottom">
                            <StackPanel>
                                <StackPanel Orientation="Horizontal">
                                    <StackPanel>
                                        <ComboBox x:Name="cmbDecodeEISType" ItemsSource="{Binding}" HorizontalContentAlignment="Stretch" Width="150">
                                            <ComboBox.ItemTemplate>
                                                <DataTemplate>
                                                    <Grid>
                                                        <TextBlock Text="{Binding EIS_Name, Mode=OneTime}" />
                                                    </Grid>
                                                </DataTemplate>
                                            </ComboBox.ItemTemplate>
                                        </ComboBox>
                                    </StackPanel>
                                    <Button x:Name="btnDecodeEIS" Content="Try Decode" Margin="10,0,0,0" />
                                </StackPanel>
                                <StackPanel Margin="0,10,0,0">
                                    <TextBlock Text="Encoded Data: " />
                                    <TextBlock x:Name="txtDecodedEISData" Text="n/a" Margin="10,3,5,5" />
                                </StackPanel>
                            </StackPanel>
                        </GroupBox>
                        <ScrollViewer>
                            <TextBlock x:Name="tbLogDetails" />
                        </ScrollViewer>
                    </DockPanel>
                </GroupBox>
            </DockPanel>
        </Grid>
    </DockPanel>
</Window>
